package com.carrey.cms_1810.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class MyInterceptor extends HandlerInterceptorAdapter{

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		//获取session中的登录对象
        Object object =  request.getSession().getAttribute("LOGIN_USER");
        if(object == null) {
             //判断，如果为空，则跳转到登录页面，否则，直接放行
             //响应重定向
             response.sendRedirect("/user/toLogin");
             return false;
        }else {
             return true;
        }
	}
}
